Patch Void type handling in Sorbet runtime for correct return types#2585
Open
Patch Void type handling in Sorbet runtime for correct return types#2585
Void type handling in Sorbet runtime for correct return types#2585Conversation
jez
reviewed
Apr 7, 2026
| module DeclBuilderPatch | ||
| def void | ||
| super.tap do | ||
| @_real_returns_is_void = true |
There was a problem hiding this comment.
fwiw, I think we could move this strategy into sorbet-runtime itself, and avoid having to patch it here. I think that adding one more true/false instance variable to the Signature data structure would not cause an increase in memory usage because of the way that Ruby buckets objects with N instance variables.
Member
Author
There was a problem hiding this comment.
Sure, something like this I assume: sorbet/sorbet#10121
I think I'll still merge this and then, later on, make the patching conditional on the existence of Signature#real_return_type method.
Since sorbet/sorbet#10064 was merged, for any sig that declares `.void.checked(:tests)`, the runtime will treat the return type as `T.anything` instead of `void` and thus break Tapioca's signature generation for methods that use this pattern. This commit adds a patch to the Sorbet runtime to ensure that the return type is correctly treated as `void` in these cases, allowing Tapioca to generate accurate signatures.
cdc6aad to
49ea080
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Superseedes #2579
Motivation
Since sorbet/sorbet#10064 was merged, for any sig that declares
.void.checked(:tests), the runtime will treat the return type asT.anythinginstead ofvoidand thus break Tapioca's signature generation for methods that use this pattern.Implementation
This commit adds a patch to the Sorbet runtime to ensure that the return type is correctly treated as
voidin these cases, allowing Tapioca to generate accurate signatures.If we ever see a
voidcall, we store a boolean flag to later on revert thevoidtoT.anythingreplacement that's done in thefinalize!method of theDeclBuilderclass, which allows Tapioca to generate proper return types for methodsTests
Added a new test for this behaviour.